<template>
  <div class="contentView" v-loading="loading" :style="`height:${contentHeight}px`">
    <div class="routeHeader mb-5px">
      <el-button @click="clickRevrt">关 闭</el-button>
    </div>
    <el-table v-loading="loading" :data="list" border :height="tableHeight">
      <el-table-column
        v-for="(item, index) in allSchemasLabel"
        :key="index"
        :label="item.label"
        :min-width="item.width"
        align="center"
        show-overflow-tooltip
      >
        <template #default="scope">
          <div v-if="item.type == 'index'">{{ scope.$index + 1 }}</div>
          <div v-else-if="item.field === 'filePath'">
            {{ scope.row.fileName }}
          </div>
          <dict-tag
            v-else-if="item.dictType"
            :type="item.dictType"
            :value="scope.row[item.field]"
          />
          <div v-else>{{ scope.row[item.field] }}</div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script setup lang="ts">
import * as ProjectTaskBookApi from '@/api/orderManagement/projectTaskBook'
import { useTagsViewStore } from '@/store/modules/tagsView'
const loading = ref(true) // 列表的加载中
const list = ref([]) // 列表的数据
const { push } = useRouter()
const total = ref(0) // 列表的总页数)
const allSchemasLabel = ref<any[]>([])
/** 查询列表 */
const getListLabel = async (id) => {
  loading.value = true
  try {
    const data = await ProjectTaskBookApi.getProjectTaskBook(id)
    allSchemasLabel.value = data.labels
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
// 返回
const tagsViewStore = useTagsViewStore()
const route = useRouter() // 路由
const clickRevrt = async () => {
  //获取当前路由并删除tagView
  tagsViewStore.delView(route.currentRoute.value)
  push('/orderManagement/orderManagement/project/projectTaskBook')
}

// 获得id
const getIdFromRoute = () => {
  const route = useRoute()
  const id = route.query.id as string
  return id ? id : null
}
const contentHeight = ref(0)
const tableHeight = ref(0)
onMounted(async () => {
  contentHeight.value = document.body.clientHeight - 127
  tableHeight.value = contentHeight.value - 70
  const id = getIdFromRoute()
  getListLabel(id)
})
</script>
<style lang="scss" scoped>
.titleSet {
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
}
</style>
